<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
</head>
<body>

    <form class="layui-form" action="#">
        <div class="layui-form-item">
            <label class="layui-form-label">类型:</label>
            <div class="layui-input-block">
                <input id="type" type="text" name="type" class="layui-input" value="{$list.type}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数据key值:</label>
            <div class="layui-input-block">
                <input id="name" type="text" name="name" class="layui-input" value="{$list.name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数据value值:</label>
            <div class="layui-input-block">
                <input id="value" type="text" name="value" class="layui-input" value="{$list.value}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父类:</label>
            <div class="layui-input-block">
                <!--<input id="press" type="text" name="press" class="layui-input" value="{$list.press}">-->
                <select id="pid" name="pid" lay-filter="pid">
                    <option value = "0">父类</option>
                    <foreach name="plist" item="vo">
                        <option value="{$vo.id}" <if condition="$vo['id'] == $list['id']">selected</if>>{$vo.type}</option>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">子类:</label>
            <div class="layui-input-block">
                <!--<input id="press" type="text" name="press" class="layui-input" value="{$list.press}">-->
                <select id="cid" name="cid">
                    <option value = "0" <if condition="0 == $list['cid']">selected</if>>子类</option>
                </select>
            </div>
        </div>
        <input id="id" name = "id" type="hidden" value="{$list.id}">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
            </div>
        </div>
    </form>
    <!-- 配置文件 -->
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        // var editor = UE.getEditor('container');
    </script>
    <script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
    <script src="__PUBLIC__/js/jquery-1.11.1.min.js" charset="utf-8"></script>
    <script type="text/javascript">
        layui.use(['form','upload'], function() {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.jquery
                , upload = layui.upload;

            //监听提交
            form.on('submit(formDemo)', function (data) {
                // alert(JSON.stringify(data.field))
                $.post('edit', data.field, function (e) {
                    if(1 == e){
                        layer.alert('提交成功', function (index) {
                            parent.location.reload();
                        });
                    }else{
                        layer.alert('提交失败，请联系管理员', function (index) {
                            //parent.location.reload();
                        });
                    }
                });
                return false;
            });
            form.on('select(pid)', function (data) {
                // alert(data.value)
                $.get("/index.php/Tongcheng/DocDicBack/getClist?pid=" + data.value, function (res) {
                    // layer.alert(JSON.stringify(res));
                    $("#cid").empty();
                    $("#cid").append("<option value = '0'>子类</option>");
                    for(var i=0;i<res.length;i++){
                        $("#cid").append("<option value = '"+res[i].id+"'>"+res[i].type+"</option>");
                    }
                    form.render('select');
                })
            });
        });
    </script>
</body>
</html>